/*
 * @页面名称: 工具函数
 * @描述:
 * @作者: 研发中心
 * @Date: 2019-12-17 09:01:09
 */
import { useDictionryStore } from "@/stores/modules/dictionary";

/**
 * @名字: 正则去掉字符串里面的大括号
 * @名字: 批处理弹框点击确定按钮触发事件
 * @详情:
 * @参数:
 * @返回值:
 */
export const removeBlock = (str: string, type?: string) => {
  let reg, reg2;
  if (str) {
    if (type === "[]") {
      reg = /\[/g;
      reg2 = /\]/g;
    } else {
      reg = /\{/g;
      // reg2 = /\}$/gi;
      reg2 = /\}/g;
    }
    str = str.replace(reg, "");
    str = str.replace(reg2, "");
    return str;
  } else {
    return str;
  }
};

/**
 * @名字: 字段转换时从数据字典中拿到的数据
 * @详情:
 * @参数: ddName:字典存储key, ddField: 代表当前key,displayField: 代表转换key, cellValue:当前value
 * @返回值:
 */
export const columnCoverter = (rule: string, cellValue: string) => {
  const dictionryStore = useDictionryStore();
  const tempObj = dictionryStore.getDictionaryObj;
  const ruleList = rule.split(":");
  const ddName = ruleList[1];
  const ddlField = ruleList[2] || "DDL_ID";
  const displayField = ruleList[3] || "DDL_Name";
  const dic = tempObj[ddName] || [];
  // eslint-disable-next-line
  const findItem = dic.find((v: any) => v[ddlField] == cellValue);
  return findItem ? findItem[displayField] : cellValue;
};
